package com.wxzz.elearing.user.api.admin;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.user.dto.EnterpriseImproveDto;
import com.wxzz.elearing.user.dto.EnterpriseImproveUpdateDto;
import com.wxzz.elearing.user.dto.MyEnterpriseImproveDto;
import com.wxzz.elearing.user.dto.SumByEnterpriseImproveDto;
import com.wxzz.elearing.user.entity.EnterpriseImprove;
import com.wxzz.elearing.user.service.IEnterpriseImproveService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/enterprise-improve")
@Api(tags = "企业改善(后台)")
public class EnterpriseImproveController {

    @Autowired
    private IEnterpriseImproveService enterpriseImproveService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = "改善审核(后台)", notes = "改善审核(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "updateEnterpriseImprove", method = RequestMethod.POST)
    public ReturnVO updateEnterpriseImprove(@RequestHeader String token, @RequestBody EnterpriseImproveUpdateDto enterpriseImproveUpdateDto) {
        return enterpriseImproveService.updateEnterpriseImprove(enterpriseImproveUpdateDto);
    }

    @ApiOperation(value = "改善列表(后台)", notes = "改善列表(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "listEnterpriseImprove", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<EnterpriseImprove>>> listEnterpriseImprove(@RequestHeader String token, @RequestBody EnterpriseImproveDto enterpriseImproveDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return enterpriseImproveService.listEnterpriseImprove(1,jsonObject.getLong("enterpriseId"),enterpriseImproveDto);
    }

    @ApiOperation(value = "改善列表(企业详情)(后台)", notes = "改善列表(企业详情)(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "listEnterpriseImprove4enterpriseDetail", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<EnterpriseImprove>>> listEnterpriseImprove4enterpriseDetail(@RequestHeader String token, @RequestBody EnterpriseImproveDto enterpriseImproveDto) {
        return enterpriseImproveService.listEnterpriseImprove(1,enterpriseImproveDto.getEnterpriseId(),enterpriseImproveDto);
    }

    @ApiOperation(value = "查询改善详情(后台)", notes = "查询改善详情(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "selectEnterpriseImproveDetail/{enterpriseImproveId}", method = RequestMethod.POST)
    public ReturnVO<EnterpriseImprove> selectEnterpriseImproveDetail(@PathVariable Long enterpriseImproveId) {
        return enterpriseImproveService.selectEnterpriseImproveDetail(enterpriseImproveId);
    }


    @ApiOperation(value = "查询该用户的改善(后台)", notes = "查询该用户的改善(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "listMyEnterpriseImprove", method = RequestMethod.POST)
    public ReturnVO listMyEnterpriseImprove( @RequestBody MyEnterpriseImproveDto myEnterpriseImproveDto) {
        return enterpriseImproveService.listMyEnterpriseImprove(myEnterpriseImproveDto.getWxUserId(),myEnterpriseImproveDto);
    }


    @ApiOperation(value = "展示当前企业改善之星(后台)", notes = "展示当前企业改善之星(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "selectSumByEnterpriseImprove", method = RequestMethod.POST)
    public ReturnVO selectSumByEnterpriseImprove(HttpServletResponse response, @RequestHeader String token, @RequestBody SumByEnterpriseImproveDto sumByEnterpriseImproveDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return enterpriseImproveService.selectSumByEnterpriseImprove(response,jsonObject.getLong("enterpriseId"), sumByEnterpriseImproveDto);
    }
}
